jQuery(document).ready(function() {

//dual box
    var db = jQuery('#dualselect').find('.ds_arrow .arrow'); //get arrows of dual select
    var sel1 = jQuery('#dualselect select:first-child'); //get first select element
    var sel2 = jQuery('#dualselect select:last-child'); //get second select element

    sel2.empty(); //empty it first from dom.

    db.click(function() {
        var t = (jQuery(this).hasClass('ds_prev')) ? 0 : 1; // 0 if arrow prev otherwise arrow next
        if (t) {
            sel1.find('option').each(function() {
                if (jQuery(this).is(':selected')) {
                    jQuery(this).attr('selected', false);
                    var op = sel2.find('option:first-child');
                    sel2.append(jQuery(this));
                }
            });
        } else {
            sel2.find('option').each(function() {
                if (jQuery(this).is(':selected')) {
                    jQuery(this).attr('selected', false);
                    sel1.append(jQuery(this));
                }
            });
        }
    });
    //FORM VALIDATION
    jQuery("#permissions-form").validate({
        rules: {
            name: "required",
            key: "required"
        },
        messages: {
            name: "Required field!",
            key: "Required fields!"
        }
    });
    jQuery("#roles-form").validate({
        rules: {
            name: "required"
        },
        messages: {
            name: "Required field!",
        }
    });
    jQuery("#members-form").validate({
        rules: {
            username: "required",
            password: {
                required: true,
                minlength: 5
            },
            re_password: {
                required: true,
                minlength: 5,
                equalTo: '#password'
            },
            displayname: "required",
            email: {
                required: true,
                email: true
            }
        }
    });

    jQuery("#reset-pass-form").validate({
        rules: {
            old_password: {
                required: true,
                minlength: 5
            },
            new_password: {
                required: true,
                minlength: 5
            },
            re_password: {
                required: true,
                minlength: 5,
                equalTo: '#new-password'
            }
        }
    });
});
